#ifndef rtps_PBufWrapper_H
#define rtps_PBufWrapper_H

#include "lwip/pbuf.h"
#include "rtps/common/types.h"

#ifdef __cplusplus
extern "C" {
#endif

enum RTPS_PBufWrapperConstructType {
    RTPS_PBW_BY_PBUF = 1,
    RTPS_PBW_BY_LENG = 2,
};

typedef struct rtps_PBufWrapper {
    struct pbuf *firstElement;
    DataSize_t m_freeSpace;
    pbuf_layer m_layer;
    pbuf_type m_type;
}rtps_PBufWrapper;

struct rtps_PBufWrapper *
rtps_PBufWrapper_Construct(enum RTPS_PBufWrapperConstructType type, ...);

void
rtps_PBufWrapper_Destruct( struct rtps_PBufWrapper *bufferWrapper);

struct rtps_PBufWrapper *
rtps_PBufWrapper_init(struct pbuf *buff);

void 
rtps_PBufWrapper_deinit(struct rtps_PBufWrapper *bufferToWrap);

bool 
rtps_PBufWrapper_isValid(struct rtps_PBufWrapper *pbw);

DataSize_t 
rtps_PBufWrapper_spaceLeft(struct rtps_PBufWrapper *pbw);

DataSize_t 
rtps_PBufWrapper_spaceUsed(struct rtps_PBufWrapper *pbw);

bool 
rtps_PBufWrapper_append(struct rtps_PBufWrapper *pbw, const uint8_t *data, DataSize_t length);

void 
rtps_PBufWrapper_append_cat(struct rtps_PBufWrapper *dstPbw, struct rtps_PBufWrapper *srcPbw);

bool 
rtps_PBufWrapper_reserve(struct rtps_PBufWrapper *pbw, DataSize_t length);

void 
rtps_PBufWrapper_reset(struct rtps_PBufWrapper *pbw);

bool 
rtps_PBufWrapper_increaseSizeBy(struct rtps_PBufWrapper *pbw, uint16_t length);

#ifdef __cplusplus
}
#endif

#endif
